{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# [Distribute Bonuses（奖金分配问题）](https://mp.weixin.qq.com/s/D5J4Qk5ILEb3AnW_pKVM2Q)\n",
    "\n",
    "You are the manager of a number of employees who all sit in a row. The CEO would like to give bonuses to all of your employees, but since the company did not perform so well this year the CEO would like to keep the bonuses to a minimum.\n",
    "\n",
    "The rules of giving bonuses is that:\n",
    "\n",
    "- Each employee begins with a bonus factor of $\\times1$.\n",
    "- For each employee, if they perform better than the person sitting next to them, the employee is given $+1$ higher bonus (and up to $+2$ if they perform better than both people to their sides).\n",
    "\n",
    "Given a list of employee's performance, find the bonuses each employee should get.\n",
    "\n",
    "&emsp;&emsp;你是一批员工的上层经理。公司总经理打算给你手下的所有员工分发奖金，但由于公司今年业绩欠佳、总经理打算让奖金总支出最小。\n",
    "\n",
    "&emsp;&emsp;奖金的发放规则如下：\n",
    "\n",
    "- 所有员工最少有1倍奖金。\n",
    "- 对于每一位员工，如果Ta表现得比相邻员工更好，可以获得额外的1倍奖金（如果Ta比相邻的其他2名员工表现都好，最高可以追加2倍奖金）。\n",
    "\n",
    "&emsp;&emsp;给定一份员工表现汇总表，确定每位员工所得的奖金额度。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Suggested Answers（参考答案）\n",
    "\n",
    "**Notice:** The following code was based on a starting template.\n",
    "\n",
    "**注意：**下方的所有代码全部基于题目给定的初始代码。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Algorithm（题解算法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getBonuses(performances: list) -> list:\n",
    "    length = len(performances)\n",
    "    bonuses = [1] * length\n",
    "    for index in range(length):\n",
    "        if (index == 0 and\n",
    "            performances[index] > performances[index + 1]):\n",
    "            bonuses[index] += 1\n",
    "        elif (index == length - 1 and\n",
    "              performances[index] > performances[index - 1]):\n",
    "            bonuses[index] += 1\n",
    "        elif 0 < index < length - 1:\n",
    "            if performances[index] > max(performances[index - 1],\n",
    "                                         performances[index + 1]):\n",
    "                bonuses[index] += 2\n",
    "            elif performances[index] > min(performances[index - 1],\n",
    "                                           performances[index + 1]):\n",
    "                bonuses[index] += 1\n",
    "    return bonuses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Test Cases（测试样例）\n",
    "\n",
    "```text\n",
    "Input: [1, 2, 3, 2, 3, 5, 1]\n",
    "Output: [1, 2, 3, 1, 2, 3, 1]\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 1, 2, 3, 1]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "getBonuses([1, 2, 3, 2, 3, 5, 1])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
